home *** CD-ROM | disk | FTP | other *** search
- #include <proto/exec.h>
- #include <proto/intuition.h>
- #include <proto/dos.h>
- #include <proto/graphics.h>
- #include <graphics/gfxmacros.h>
- #include <exec/memory.h>
- #include <stdio.h>
- #include <string.h>
- #include <tools.h>
- #include <proto/translator.h>
- #include <devices/narrator.h>
- #include "bppro.h"
-
- #define MakeID(a,b,c,d) ( (LONG)(a)<<24L | (LONG)(b)<<16L | (c)<<8 | (d) )
-
- #define ID_YAKK MakeID('Y','A','K','K')
-
- /*
- ** include PowerWindows window definition
- */
- #pragma msg 62 ignore push
-
- #include "yakpw.c"
-
- #pragma msg 62 pop
-
- extern struct Functions *functions;
-
- /*
- ** The Tool's icon
- */
- static UWORD chip Yak[]=
- {
- /*-------- plane # 0 --------*/
-
- 0x0000, 0x0000,
- 0x3fff, 0xff00,
- 0x3000, 0x0300,
- 0x37e1, 0xfb00,
- 0x3e73, 0x9f00,
- 0x37e1, 0xfb00,
- 0x3000, 0x0300,
- 0x3000, 0x0300,
- 0x3000, 0x0300,
- 0x3000, 0x0300,
- 0x3fff, 0xff00,
- 0x0000, 0x0000,
-
- /*-------- plane # 1 --------*/
-
- 0x0000, 0x0000,
- 0x0000, 0x0100,
- 0x081e, 0x0700,
- 0x081e, 0x0700,
- 0xc00c, 0x0300,
- 0xc81e, 0x0700,
- 0xcfff, 0xff00,
- 0xcfff, 0xff00,
- 0x0fff, 0xff00,
- 0x0fff, 0xff00,
- 0x1fff, 0xff00,
- 0x0000, 0x0000,
-
- /*-------- plane # 2 --------*/
-
- 0x0000, 0x0000,
- 0x0000, 0x0000,
- 0x0000, 0x0000,
- 0x0000, 0x0000,
- 0x0180, 0x6000,
- 0x0000, 0x0000,
- 0x003f, 0x0000,
- 0x0040, 0x8000,
- 0x0040, 0x8000,
- 0x003f, 0x0000,
- 0x0000, 0x0000,
- 0x0000, 0x0000
- };
-
- static struct Image Yakimage=
- {
- 0,0,24,12,3,
- Yak,
- 0x7,0x0,NULL
- };
-
- #define STRINGSIZE 100 /* max size for each string */
- #define COMMENTSIZE 30 /* max size for label */
- #define ITEMHEIGHT 10 /* vertical size in display list */
-
- typedef struct YakTool
- {
- struct Tool tool;
- char *strings[128];
- char *comments[128];
- unsigned char topindent;
- unsigned char selectedvalue;
- } YakTool;
-
- #pragma msg 72 ignore push
- struct Library *TranslatorBase; /* need this to call Translate() */
- #pragma msg 72 pop
- static struct ToolMaster master; /* out ToolMaster struct */
- static struct MsgPort *yakport; /* port for process to receive messages */
-
- typedef struct YakMessage
- {
- struct Message message; /* Exec message. */
- YakTool *tool; /* Tool to perform io. */
- unsigned char value; /* Note value. */
- unsigned char vel; /* Note velocity */
- } YakMessage;
-
- #define PORTNAME "YakPort"
-
- /*
- ** void talk(char *string,short vel)
- **
- ** char *string; string to "speak"
- ** char *vel; velocity of the note, used for a volume
- **
- */
- void talk(char *string,short vel)
- {
- char speech[200]; /* translate buffer */
- struct MsgPort *WPort;
- struct narrator_rb *wmes;
- static char masks[]={3,5,10,12}; /* audio channel masks to try */
-
- Translate(string,strlen(string),speech,sizeof(speech));
- WPort=(struct MsgPort *)CreatePort(NULL,0);
- if(WPort)
- {
- wmes=(struct narrator_rb *)CreateExtIO(WPort,sizeof(struct narrator_rb));
- if(wmes)
- {
- wmes->ch_masks=masks;
- wmes->nm_masks=sizeof(masks);
- if(!(OpenDevice("narrator.device",0,(struct IORequest *)wmes,0)))
- {
- wmes->mouths=1;
- wmes->volume=(vel+1)>>1;
- /*
- set up for default values
- */
- wmes->rate=DEFRATE;
- wmes->pitch=DEFPITCH;
- wmes->mode=DEFMODE;
- wmes->sex=DEFSEX;
- wmes->sampfreq=DEFFREQ;
- wmes->message.io_Command=CMD_WRITE;
- wmes->message.io_Data=speech;
- wmes->message.io_Length=strlen(speech);
- DoIO((struct IORequest *)wmes);
- CloseDevice((struct IORequest *)wmes);
- }
- DeleteExtIO((struct IORequest *)wmes);
- }
- DeletePort(WPort);
- }
- }
-
- /*
- ** void yakprocess(void)
- **
- ** This is the process started up by the Yak Tool. It does all
- ** I/O to the narrator device.
- */
- static void yakprocess(void)
- {
- YakMessage *mm;
- YakTool *tool;
- char value,vel;
-
- TranslatorBase=OpenLibrary("translator.library",0);
- if(TranslatorBase==NULL)
- return;
- yakport=CreatePort(PORTNAME,0);
- if(yakport==NULL)
- {
- CloseLibrary(TranslatorBase);
- return;
- }
- for(;;)
- {
- mm=(YakMessage *)GetMsg(yakport);
- if(mm==NULL)
- {
- WaitPort(yakport);
- mm=(YakMessage *)GetMsg(yakport);
- }
- tool=mm->tool;
- value=mm->value;
- vel=mm->vel;
-
- /* don't reply - I can free it since I created it */
-
- functions->myfree((void *)mm,sizeof(YakMessage));
-
- if(tool==NULL) /* message to quit process */
- break;
- talk(tool->strings[value],vel);
- }
- DeletePort(yakport);
- CloseLibrary(TranslatorBase);
-
- /* set yakport to NULL to indicate that this process has ended */
- yakport=NULL;
- }
-
- /*
- ** ret=sendcommand(YakTool *tool,unsigned char value,unsigned char vel);
- **
- ** YakTool *tool; the tool sending the message
- ** unsigned char value; the note value
- ** unsigned char vel; the note velocity
- **
- ** Sends a message to our process. returns non-zero on success.
- */
- static long sendcommand(YakTool *tool,unsigned char value,unsigned char vel)
- {
- YakMessage *message;
- struct MsgPort *iport=(struct MsgPort *)FindPort(PORTNAME);
-
- if(iport)
- {
- message=(YakMessage *)functions->myalloc(sizeof(YakMessage),MEMF_CLEAR);
- if(message)
- {
- message->tool=tool;
- message->value=value;
- message->vel=vel;
- PutMsg(iport,(struct Message *)message);
- return 1;
- }
- }
- return 0;
- }
-
- /*
- ** struct Event *processeventcode(struct Event *event);
- **
- ** The Tool's processevent routine.
- */
- static struct Event *processeventcode(struct Event *event)
- {
- YakTool *tool=(YakTool *)event->tool;
-
- /*
- if the event is a NOTE ON and the string to speak is not blank or NULL,
- send a command to speak it.
- */
- if(event->status==MIDI_NOTEON &&
- tool->strings[event->byte1]!=NULL && tool->strings[event->byte1][0]!='\0')
- sendcommand(tool,event->byte1,event->byte2);
- event->tool=tool->tool.next;
- return event;
- }
-
- /*
- ** static void computenewsize(struct Window *window);
- **
- ** adjusts the height of the display list gadget after a window
- ** resixe operation.
- */
- static void computenewsize(struct Window *window)
- {
- struct Gadget *gadget;
- struct RastPort *rp=window->RPort;
-
- gadget=(struct Gadget *)functions->GetGadget(window,4);
- SetDrMd(rp,JAM2);
- SetAPen(rp,0);
- BNDRYOFF(rp);
- RectFill(rp,gadget->LeftEdge-2,gadget->TopEdge,1+gadget->LeftEdge+gadget->Width,
- gadget->TopEdge+gadget->Height);
- functions->EmbossOff(window,4);
- gadget->Height=window->Height-gadget->TopEdge-4;
- functions->EmbossOn(window,4,0);
- }
-
- /*
- ** static void setscrollbar(struct Window *window,YakTool *tool);
- **
- ** sets the scroll bar for the display list to the proper level.
- */
- static void setscrollbar(struct Window *window,YakTool *tool)
- {
- struct Gadget *gadget=(struct Gadget *)functions->GetGadget(window,4);
- unsigned long height=(window->Height-gadget->TopEdge)/ITEMHEIGHT;
-
- if((tool->topindent+height)>=128)
- tool->topindent=128-height;
- functions->ModifyWindowProps(window,0,tool->topindent,0,128,0,height);
- functions->RefreshEmbossedWindowFrame(window);
- }
-
- /*
- ** static void drawstringlist(struct Window *window,YakTool *tool);
- **
- ** draws the display list.
- */
- static void drawstringlist(struct Window *window,YakTool *tool)
- {
- struct RastPort *rp=window->RPort;
- struct Gadget *gadget=(struct Gadget *)functions->GetGadget(window,4);
- short y=gadget->TopEdge+ITEMHEIGHT-1;
- short index;
- short bottom=window->Height-ITEMHEIGHT-3;
- char name[8],*p;
- char text[120];
-
- SetDrMd(rp,JAM2);
- SetBPen(rp,2);
- for(index=tool->topindent ; index<128 ; ++index)
- {
- Move(rp,10,y-2);
- if(index==tool->selectedvalue)
- SetAPen(rp,6);
- else
- SetAPen(rp,4);
- functions->notetostring(0,index,name);
-
- /* if there's a label, use that */
-
- if(tool->comments[index] && tool->comments[index][0])
- p=tool->comments[index];
-
- /* else if there's text to speak, use that */
-
- else if(tool->strings[index] && tool->strings[index][0])
- p=tool->strings[index];
-
- /* otherwise, it's empty */
-
- else
- p="« empty »";
-
- sprintf(text,"%4s:%-22.22s",name,p);
- Text(rp,text,27);
- if(y>=bottom)
- break;
- y+=ITEMHEIGHT;
- }
- }
-
- static YakTool *dragtool;
-
- /*
- ** static vroutine(struct Window *window,struct Gadget *gadget,unsigned long x,unsigned long y);
- **
- ** callback routine for dragging the scrollbar of the display list.
- */
- static vroutine(struct Window *window,struct Gadget *gadget,unsigned long x,unsigned long y)
- {
- if(dragtool)
- {
- if(dragtool->topindent!=y)
- {
- dragtool->topindent=y;
- drawstringlist(window,dragtool);
- }
- }
- return (long)y;
- }
-
- /*
- ** static void setstrings(YakTool *tool);
- **
- ** This routine makes sure that the current string and label are non-NULL
- ** and also frees any blank strings it finds elsewhere.
- */
- static void setstrings(YakTool *tool)
- {
- short index;
- char *s;
-
- for(index=0 ; index<128 ; ++index)
- {
- if(index==tool->selectedvalue)
- {
- if(!tool->strings[index])
- tool->strings[index]=(void *)functions->myalloc(STRINGSIZE,MEMF_CLEAR);
- if(!tool->comments[index])
- tool->comments[index]=(void *)functions->myalloc(COMMENTSIZE,MEMF_CLEAR);
- }
- else
- {
- if(s=tool->strings[index])
- {
- if(!s[0])
- {
- functions->myfree(s,STRINGSIZE);
- tool->strings[index]=NULL;
- }
- }
- if(s=tool->comments[index])
- {
- if(!s[0])
- {
- functions->myfree(s,COMMENTSIZE);
- tool->comments[index]=NULL;
- }
- }
- }
- }
- }
-
- /*
- ** static short indextostring(struct Window *window,YakTool *tool,short y);
- **
- ** based on the mouse Y position, return the item # in the display list
- ** that was selected.
- */
- static short indextostring(struct Window *window,YakTool *tool,short y)
- {
- struct Gadget *gadget=(struct Gadget *)functions->GetGadget(window,4);
-
- y-=gadget->TopEdge;
- y/=ITEMHEIGHT;
- y+=tool->topindent;
- return y;
- }
-
- /*
- ** static long sizetool(YakTool *tool);
- **
- ** return the total size of the tool for save purposes.
- */
- static long sizetool(YakTool *tool)
- {
- long size=sizeof(YakTool);
- short id;
-
- for(id=0 ; id<128 ; ++id)
- {
- if(tool->strings[id])
- size+=STRINGSIZE;
- if(tool->comments[id])
- size+=COMMENTSIZE;
- }
- return size;
- }
-
- /*
- ** static long savetool(long file,YakTool *tool);
- **
- ** save the tool and the dynamically allocated strings to the file
- */
- static long savetool(long file,YakTool *tool)
- {
- long id=ID_YAKK;
-
- functions->fastwrite(file,(char *)&id,4);
- id=sizetool(tool);
- functions->fastwrite(file,(char *)&id,4);
- if(functions->fastwrite(file,(char *)tool,sizeof(YakTool))==-1)
- return 1;
- for(id=0 ; id<128 ; ++id)
- {
- if(tool->strings[id])
- {
- if(functions->fastwrite(file,tool->strings[id],STRINGSIZE)==-1)
- return 1;
- }
- }
- for(id=0 ; id<128 ; ++id)
- {
- if(tool->comments[id])
- {
- if(functions->fastwrite(file,tool->comments[id],COMMENTSIZE)==-1)
- return 1;
- }
- }
- return 0;
- }
-
- /*
- ** static struct Tool *loadtool(long file,long size);
- **
- ** load the tool and read in strings as necessary.
- */
- static struct Tool *loadtool(long file,long size)
- {
- YakTool *tool=(YakTool *)functions->myalloc(sizeof(YakTool),MEMF_CLEAR);
- short i;
-
- if(tool)
- {
- functions->fastread(file,(char *)tool,sizeof(YakTool));
- size-=sizeof(YakTool);
- for(i=0 ; i<128 ; ++i)
- {
- if(tool->strings[i])
- {
- tool->strings[i]=(void *)functions->myalloc(STRINGSIZE,0);
- if(tool->strings[i])
- {
- functions->fastread(file,tool->strings[i],STRINGSIZE);
- size-=STRINGSIZE;
- }
- }
- }
- for(i=0 ; i<128 ; ++i)
- {
- if(tool->comments[i])
- {
- tool->comments[i]=(void *)functions->myalloc(COMMENTSIZE,0);
- if(tool->comments[i])
- {
- functions->fastread(file,tool->comments[i],COMMENTSIZE);
- size-=COMMENTSIZE;
- }
- }
- }
- }
- functions->fastseek(file,size,0);
- return (struct Tool *)tool;
- }
-
- /*
- ** static void cleartool(YakTool *tool);
- **
- ** reset all strings to be blank and free their memory.
- */
- static void cleartool(YakTool *tool)
- {
- short i;
-
- for(i=0 ; i<128 ; ++i)
- {
- if(tool->strings[i])
- {
- functions->myfree(tool->strings[i],STRINGSIZE);
- tool->strings[i]=NULL;
- }
- if(tool->comments[i])
- {
- functions->myfree(tool->comments[i],COMMENTSIZE);
- tool->comments[i]=NULL;
- }
- }
- }
-
- /*
- ** static struct Tool *createtool(YakTool *copy);
- **
- ** create a tool and handle making a copy
- */
- static struct Tool *createtool(YakTool *copy)
- {
- YakTool *tool=(YakTool *)functions->myalloc(sizeof(YakTool),MEMF_CLEAR);
- short i;
-
- if(tool)
- {
- if(copy)
- {
- *tool=*copy;
- tool->tool.next=NULL;
- for(i=0 ; i<128 ; ++i)
- {
- if(copy->strings[i])
- {
- tool->strings[i]=(void *)functions->myalloc(STRINGSIZE,MEMF_CLEAR);
- if(tool->strings[i])
- memcpy(tool->strings[i],copy->strings[i],STRINGSIZE);
- }
- if(copy->comments[i])
- {
- tool->comments[i]=(void *)functions->myalloc(COMMENTSIZE,MEMF_CLEAR);
- if(tool->comments[i])
- memcpy(tool->comments[i],copy->comments[i],COMMENTSIZE);
- }
- }
- }
- }
- return (struct Tool *)tool;
- }
-
- /*
- ** static void deletetool(YakTool *tool);
- **
- ** delete a tool and free all dynamically allocated memory
- */
- static void deletetool(YakTool *tool)
- {
- cleartool(tool);
- functions->myfree((char *)tool,sizeof(YakTool));
- }
-
- /*
- ** static long loadYakTool(YakTool *tool);
- **
- ** load a list of text previously saved.
- **
- ** To save time and code this is implemented by just saving the whole
- ** tool, loading it in, grabbing what is needed from the loaded in tool,
- ** and then freeing the loaded tool.
- */
- static long loadYakTool(YakTool *tool)
- {
- long file;
- char filename[100];
- YakTool *newtool=NULL;
- long id, size;
-
- functions->FileName(filename,"Load List:","yaklist",functions->screen,
- FILES_OPEN|FILES_DELETE,0,0);
- if(filename[0])
- {
- file=functions->fastopen(filename,MODE_OLDFILE);
- if(file)
- {
- functions->openwait();
- functions->fastread(file,(char *)&id,4);
- functions->fastread(file,(char *)&size,4);
- if(id==ID_YAKK)
- {
- newtool=(struct YakTool *)loadtool(file,size);
- if(newtool)
- {
- cleartool(tool);
- for(id=0 ; id<128 ; ++id)
- tool->strings[id]=newtool->strings[id];
- for(id=0 ; id<128 ; ++id)
- tool->comments[id]=newtool->comments[id];
- functions->myfree((char *)newtool,sizeof(struct YakTool));
- }
- }
- functions->fastclose(file);
- functions->closewait();
- }
- }
- return (newtool!=NULL);
- }
-
- /*
- ** static void saveYakTool(YakTool *tool);
- **
- ** saves the list of text currently defined. (see loadYakTool).
- */
- static void saveYakTool(YakTool *tool)
- {
- char filename[100];
- long file;
-
- functions->FileName(filename,"Save List:","yaklist",functions->screen,
- FILES_SAVE|FILES_DELETE,0,0);
- if(filename[0])
- {
- file=functions->fastopen(filename,MODE_NEWFILE);
- if(file)
- {
- functions->openwait();
- savetool(file,tool);
- functions->closewait();
- functions->fastclose(file);
- }
- }
- }
-
- /*
- ** void assignhits(YakTool *tool);
- **
- ** This assigns the hitlist based on the text stored in the tool.
- */
- void assignhits(YakTool *tool)
- {
- struct HitName *top,*prev,*hn,*hp;
- short i;
- char *p;
-
- top=NULL;
- for(i=0 ; i<128 ; ++i)
- {
- /* If there's a label, use that */
- if(tool->comments[i] && tool->comments[i][0])
- p=tool->comments[i];
-
- /* otherwise just use the text */
- else if(tool->strings[i] && tool->strings[i][0])
- p=tool->strings[i];
-
- /* if no text, skip this note */
- else
- p=NULL;
- if(p)
- {
- hn=(void *)functions->myalloc(sizeof(struct HitName),MEMF_CLEAR);
- if(hn)
- {
-
- /* insert the hit into the list sorted by the hit name */
-
- hn->note=i;
- strncpy(hn->name,p,sizeof(hn->name)-1);
- if(top==NULL)
- top=hn;
- else
- {
- prev=NULL;
- for(hp=top ; hp!=NULL ; hp=hp->next)
- {
- if(stricmp(hp->name,hn->name)>=0)
- break;
- prev=hp;
- }
- if(prev)
- {
- hn->next=prev->next;
- prev->next=hn;
- }
- else
- {
- hn->next=top;
- top=hn;
- }
- }
- }
- }
- }
-
- /* install the hit list */
-
- functions->installhitlist(tool->tool.track,top);
- }
-
- /*
- ** void edittoolcode(YakTool *tool);
- **
- ** open the YakTool editing window & edit the tool info.
- */
- void edittoolcode(YakTool *tool)
- {
- struct IntuiMessage *message;
- struct Window *window;
- long class,code;
- struct Gadget *gadget;
- struct NewWindow *newwindow;
- char refresh=1;
- short mousey,menunum,itemnum;
- struct MenuItem *item;
- char notename[20];
- struct StringInfo *stringinfo;
-
- if(!tool->tool.touched)
- {
- tool->topindent=tool->selectedvalue=60;
- }
- yakNewWindowStructure1.Screen=functions->screen;
- if(tool->tool.touched & TOUCH_EDIT)
- {
- yakNewWindowStructure1.LeftEdge=tool->tool.left;
- yakNewWindowStructure1.TopEdge=tool->tool.top;
- }
-
- /*
- duplicate the newwindow struct since each tool needs it's own copy
- */
- newwindow=(struct NewWindow *)functions->DupeNewWindow(&yakNewWindowStructure1);
- if(!newwindow)
- return;
-
- /*
- set up newwindow flags for B&P Pro look
- */
- newwindow->Title=NULL;
- newwindow->Flags|=BORDERLESS;
- newwindow->Flags&=~0xF;
- newwindow->DetailPen=0;
- newwindow->BlockPen=0;
- window=(struct Window *)functions->FlashyOpenWindow(newwindow);
- if(!window)
- {
- functions->DeleteNewWindow(newwindow);
- return;
- }
- SetMenuStrip(window,&yakMenu1);
- tool->tool.window=window;
-
- /*
- turn on the B&P Pro border
- */
- functions->EmbossWindowOn(window,WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|WINDOWSIZING,
- "Yak",(short)-1,38,0,(void *)vroutine);
- functions->EmbossOn(window,1,3);
- functions->EmbossOn(window,3,3);
- functions->EmbossOn(window,4,0);
- computenewsize(window);
- for(;;)
- {
- if(refresh)
- {
- setstrings(tool);
- /*
- refresh the string gadgets to reflect the currently
- selected note
- */
- functions->notetostring(0,tool->selectedvalue,notename);
- gadget=(struct Gadget *)functions->GetGadget(window,1);
- sprintf(gadget->GadgetText->IText,"%4s:",notename);
- stringinfo=(void *)functions->GetStringInfo(window,1);
- stringinfo->Buffer=tool->strings[tool->selectedvalue];
- functions->RefreshGadget(window,1);
- stringinfo=(void *)functions->GetStringInfo(window,3);
- stringinfo->Buffer=tool->comments[tool->selectedvalue];
- functions->RefreshGadget(window,3);
- /*
- make sure the display list is displayed properly
- */
- setscrollbar(window,tool);
- drawstringlist(window,tool);
- if(refresh==2)
- ActivateGadget((struct Gadget *)functions->GetGadget(window,1),window,0);
- refresh=0;
- }
- message=(struct IntuiMessage *)functions->GetIntuiMessage(window);
- class=message->Class;
- code=message->Code;
- mousey=message->MouseY;
- gadget=(struct Gadget *)message->IAddress;
- dragtool=tool;
- /*
- call B&P Pro system gadget handler - it handles thing like the
- close gadget & the front/back gadget as well as scrollbars
- */
- class=functions->SystemGadgets(window,class,gadget,code);
- dragtool=NULL;
- ReplyMsg((struct Message *)message);
- if(class==CLOSEWINDOW)
- break;
- else if(class==NEWSIZE)
- {
- setscrollbar(window,tool);
- computenewsize(window);
- refresh=1;
- }
- else if(class==GADGETDOWN)
- {
- switch(gadget->GadgetID)
- {
- case 4: /* clicked on the display list, select a new note */
- tool->selectedvalue=indextostring(window,tool,mousey) & 0x7F;
- refresh=2;
- break;
- }
- }
- else if(class==GADGETUP)
- {
- switch(gadget->GadgetID)
- {
- case 1: /* the text string */
- ActivateGadget((struct Gadget *)functions->GetGadget(window,3),window,0);
- drawstringlist(window,tool);
- assignhits(tool);
- break;
- case 3: /* the label, increment the selected note */
- ++tool->selectedvalue;
- tool->selectedvalue&=0x7F;
- tool->topindent=tool->selectedvalue;
- if(tool->topindent>0)
- --tool->topindent;
- refresh=2;
- assignhits(tool);
- break;
- }
- }
- else if(class==MENUPICK)
- {
- while(code!=MENUNULL)
- {
- menunum=MENUNUM(code);
- itemnum=ITEMNUM(code);
- item=(struct MenuItem *)ItemAddress(window->MenuStrip,code);
- code=item->NextSelect;
- if(menunum==0)
- {
- switch(itemnum)
- {
- case 0: /* New. */
- if(functions->areyousure("Clear this list?"))
- {
- cleartool(tool);
- refresh=1;
- }
- assignhits(tool);
- break;
- case 1: /* Load. */
- /*
- must do a functions->doscall() to do DOS functions since we
- are only a lowly Task.
- */
- if(functions->areyousure("Replace this list?"))
- refresh=functions->doscall(loadYakTool,tool);
- assignhits(tool);
- break;
- case 2: /* Save. */
- functions->doscall(saveYakTool,tool);
- break;
- }
- }
- }
- }
- }
- /*
- turn off all B&P Pro embossed buttons & window embossing
- */
- functions->EmbossOff(window,1);
- functions->EmbossOff(window,3);
- functions->EmbossOff(window,4);
- functions->EmbossWindowOff(window);
- tool->tool.window=0;
- tool->tool.left=window->LeftEdge;
- tool->tool.top=window->TopEdge;
- tool->tool.touched=TOUCH_INIT|TOUCH_EDIT;
- /*
- close the window & get out.
- */
- ClearMenuStrip(window);
- functions->FlashyCloseWindow(window);
- functions->DeleteNewWindow(newwindow);
- }
-
- /*
- ** void removetool(void);
- **
- ** handle removing the tool.
- */
- void removetool(void)
- {
- sendcommand(NULL,0,0); /* close down the process */
- while(yakport!=NULL)
- WaitTOF(); /* wait till the process is done */
- WaitTOF(); /* just to make ABSOLUTELY sure */
- }
-
- typedef struct CodeHdr
- {
- ULONG SegSize;
- ULONG NextSeg;
- UWORD JumpInstr;
- APTR Function;
- } CodeHdr;
-
- #define T_BPTR(x) ((BPTR)(((ULONG)(x))>>2))
-
- /*
- ** static long StartProcess(char *name,short priority,APTR code,long stacksize);
- **
- ** this is a WB 1.3 compatible way to start a new process.
- */
- static long StartProcess(char *name,short priority,APTR code,long stacksize)
- {
- static __aligned CodeHdr chead;
-
- chead.SegSize=sizeof(CodeHdr);
- chead.JumpInstr=0x4EF9;
- chead.Function=code;
- return (long)CreateProc(name,priority,T_BPTR(&chead.NextSeg),stacksize);
- }
-
- /*
- ** static long mmfunc(YakTool *tool,long cmd);
- **
- ** handle multimediafunc() commands
- */
- static long mmfunc(YakTool *tool,long cmd)
- {
- if(cmd==MMCMD_INSTALLHITLIST)
- {
- assignhits(tool);
- return 1;
- }
- return 0;
- }
-
- /*
- ** struct ToolMaster *inittoolmaster(void);
- **
- ** initialize the Yak tool.
- */
- struct ToolMaster *inittoolmaster(void)
- {
- if(FindPort(PORTNAME)) /* I'm already loaded, don't load again */
- return NULL;
-
- strcpy(master.name,"Yak");
- master.toolid =ID_YAKK;
- master.image =&Yakimage;
- master.edittool =edittoolcode;
- master.processevent=processeventcode;
- master.deletetool =deletetool;
- master.loadtool =loadtool;
- master.savesize =sizetool;
- master.savetool =savetool;
- master.createtool =createtool;
- master.removetool =removetool;
- master.multimediafunc=mmfunc;
- master.tooltype =TOOL_OUTPUT|TOOL_ONTIME;
- master.toolsize =sizeof(YakTool);
-
- /* start up the process to do narrator device I/O */
-
- if(!StartProcess("YakProc",0,yakprocess,6000))
- return NULL;
-
- return &master;
- }
-